<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

$default_dir = "./Fotos";
$default_dir_thumb = "Thumbnails";
$contador = 0;
$default_max_thumb = 10; 
$image_file_array = array("gif","jpeg","jpg","png");


function date_str($timestamp){
        $date_str = getdate($timestamp);
        $year =     $date_str["year"];
        $mon =      $date_str["mon"];
        $mday =     $date_str["mday"];
        $hours =    $date_str["hours"];
        $minutes =  $date_str["minutes"];
        $seconds =  $date_str["seconds"];
        return "$mday/$mon/$year  $hours:$minutes:$seconds";
        
     }


function lista_diretorio(){
    
    global $default_dir;
    
    if(!($dp = opendir($default_dir))) die("Não foi possível Abrir $default_dir");
     
        while($file = readdir($dp)) $filenames[] = $file;
        closedir($dp);
        sort($filenames);
        echo "<ul>";
        
        for($i = 0; $i <count($filenames); $i++)
        {
            if($filenames[$i] != '.' && $filenames[$i] != '..')
            {
                if(is_dir("$default_dir/$filenames[$i]"))
                {
                    echo "<li><a href=\"$PHP_SELF?folder=$filenames[$i]\">$filenames[$i]/</a></li>";  
                    
                }
            }
        }
        
        echo "</ul>";        
}



function list_thumb($path)
{
    global $default_dir,$default_dir_thumb,$default_max_thumb,$contador,$show,$image_file_array;
    
    echo "<h2 class=\"title\"><a href=\"#\">$path</a></h2>";
    if($show){
        
        if(!($dp = opendir("$default_dir/$path/$default_dir_thumb"))) die("Não foi possível Abrir $path");
    
        while($file = readdir($dp)) $filenames[] = $file;
        closedir($dp);
        sort($filenames);
        $totalImagens = count($filenames);
        $dataDiretorio = date_str(filectime("$default_dir/$path/$default_dir_thumb"));
        $uniqueIdentifier = md5($path);
       
        echo "<p class=\"meta\"><span class=\"date\">$dataDiretorio</span><span class=\"posted\">UID <a href=\"#\">$uniqueIdentifier</a></span></p>";
        echo "<div style=\"clear: both;\">&nbsp;</div>";
        echo "<div class=\"entry\">";
        echo "<p>";	
        echo "<ul>";
        
        for($i = 0; $i <$totalImagens; $i++)
        {
            if($filenames[$i] != '.' && $filenames[$i] != '..')
            {
                
                 $extension = array_pop(explode(".",$filename));
          
                if(is_file("$default_dir/$path/$default_dir_thumb/$filenames[$i]"))
                {
                    
                    $extension = array_pop(explode(".",$filenames[$i]));
                     if(in_array($extension, $image_file_array)){
                    
                            echo "<li style=\"display:inline;margin:6px;\"><img src=\"$default_dir/$path/$default_dir_thumb/$filenames[$i]\"></li>";  
                            $contador++;
                            if ($contador >= $default_max_thumb){break;}
                     }
                }
            }
        }
        
        
        echo "</ul>";
        echo"</p>";
        echo "</div>";
        }
}
?>
